home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1.1 / The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso / 32 / tictacai.zip / TTSUBS.ASM < prev   
Assembly Source File  |  1990-06-17  |  9KB  |  346 lines

  1.  
  2. ;*****************************************************************************
  3. ;
  4. ; TTSUBS.ASM
  5. ;
  6. ; Copyright (C) 1990 by Aaron L. Brenner
  7. ;
  8. ; Purpose:
  9. ;    Subroutines for TICTAC.C
  10. ;
  11. ; Contents:
  12. ;    mouse_init()        Initialize the mouse.
  13. ;    mouse_on()        Turns mouse processing on.
  14. ;    mouse_off()        Turns mouse processing off.
  15. ;    mouse_bounds()        Set the mouse cursor boundaries.
  16. ;    mouse_cursor()        Turn the mouse cursor on or off.
  17. ;    mouse_buttons()        Get the state of the mouse buttons.
  18. ;    mouse_in_region()    Determine whether or not the mouse is in a
  19. ;                region.
  20. ;
  21. ; Revision history:
  22. ; 1.00    06/13/90    ALB    Created.
  23. ;
  24. ;*****************************************************************************
  25.  
  26.     include    mixed.inc
  27.  
  28. clang    equ    0
  29.  
  30.     ifndef    model
  31. model    equ    <small>
  32.     endif
  33.  
  34.     setmodel
  35.  
  36. ;*****************************************************************************
  37. ;
  38. ; The mouse_info array gets set by our int handler, and is structured:
  39. ;
  40. ;*****************************************************************************
  41. mseinfo        struc
  42.  mi_flags    db    ?        ; Bit flags:
  43.                     ;  bit 0 = 1    Mouse present
  44.                     ;  bit 1 = 1    Mouse handling ON
  45.  mi_buttons    db    ?        ; Button status
  46.  mi_row        db    ?        ; Current cursor row
  47.  mi_col        db    ?        ; Current cursor column
  48. mseinfo        ends
  49.  
  50.  
  51. ;*****************************************************************************
  52. ;
  53. ; Structure used to define screen regions
  54. ;
  55. ;*****************************************************************************
  56. REGION        struc
  57.  r_ulrow    db    ?        ; Upper left row
  58.  r_ulcol    db    ?        ; Upper left column
  59.  r_lrrow    db    ?        ; Lower right row
  60.  r_lrcol    db    ?        ; Lower right column
  61. REGION        ends
  62.  
  63.     .data
  64. mouse_info    mseinfo<0, 0, 0, 0>
  65.  
  66.     .code
  67.  
  68. ;*****************************************************************************
  69. ;
  70. ; This is the user interrupt routine set by Fn 12. All it does is record the
  71. ; information passed by the mouse driver.
  72. ;
  73. ;*****************************************************************************
  74. mse_int        proc    far
  75.  
  76.     push    ds            ; Save it; it's the mouse driver's seg
  77.     mov    ax,DGROUP        ; Get our data segment
  78.     mov    ds,ax            ;
  79.     test    mouse_info.mi_flags,2    ; Should we pay attention?
  80.     jz    msei_exit        ; No - ignore this stuff
  81.     mov    mouse_info.mi_buttons,bl; Save the button state
  82.     mov    ax,cx            ; Get the column
  83.     mov    cl,3            ; Divide row and column by 8
  84.     shr    ax,cl            ;  since mse driver reports pixel
  85.     mov    mouse_info.mi_col,al    ;  positions instead of text char
  86.     shr    dx,cl            ;  positions
  87.     mov    mouse_info.mi_row,dl    ; Save the row
  88. msei_exit:
  89.     pop    ds            ; Restore their segment
  90.     ret                ; Return to mouse driver
  91.  
  92. mse_int        endp
  93.  
  94. ;*****************************************************************************
  95. ;
  96. ; int mouse_init(void)
  97. ;
  98. ; Purpose:
  99. ;    Initializes the mouse, setting a user int handler.
  100. ;
  101. ; Input:
  102. ;    None.
  103. ;
  104. ; Output:
  105. ;    Function returns non-zero if there is a mouse.
  106. ;
  107. ;*****************************************************************************
  108. hproc    mouse_init <uses ax bx cx dx es>
  109.  
  110.     sub    ax,ax            ; Fn 0 - Reset mouse driver
  111.     mov    mouse_info.mi_flags,al    ; Clear the flag
  112.     int    33h            ;
  113.     or    ax,ax            ; Is there a mouse?
  114.     jz    hkms_exit        ; Nope - just exit
  115.     and    al,1            ; Just use the low bit
  116.     mov    mouse_info.mi_flags,al    ; Set the flag saying we have one
  117.     push    cs            ; Need segment of the routine
  118.     pop    es            ;
  119.     mov    dx,offset mse_int    ; Address of routine to call
  120.     mov    cx,0000000000011110b    ; Call mask (any button activity)
  121.     mov    ax,12            ; Fn 1 - Set user int sub
  122.     int    33h            ;
  123. hkms_exit:
  124.     mov    al,mouse_info.mi_flags    ; Get the presence flag
  125.     sub    ah,ah            ;  to return
  126.     hret                ; Return to caller
  127.  
  128. hendp
  129.  
  130.  
  131. ;*****************************************************************************
  132. ;
  133. ; void mouse_on(void)
  134. ;
  135. ; Purpose:
  136. ;    Turn mouse processing on. This turns the mouse cursor on, and tells
  137. ;    our int handler to start noticing what the mouse is doing.
  138. ;
  139. ; Input:
  140. ;    None.
  141. ;
  142. ; Output:
  143. ;    Mouse processing is enabled.
  144. ;
  145. ;*****************************************************************************
  146. hproc    mouse_on <uses ax>
  147.  
  148.     test    mouse_info.mi_flags,1    ; Do we have a mouse?
  149.     jz    mson_exit        ; No - never mind
  150.     mov    ax,1            ; Turn the cursor on
  151.     int    33h            ;
  152.     cli                ; Disallow ints for a sec
  153.     or    mouse_info.mi_flags,2    ; Enable our processing of mouse
  154.     sti                ;
  155. mson_exit:
  156.     hret                ; Return to caller
  157.  
  158. hendp
  159.  
  160.  
  161. ;*****************************************************************************
  162. ;
  163. ; void mouse_off(void)
  164. ;
  165. ; Purpose:
  166. ;    Disables further mouse processing.
  167. ;
  168. ; Input:
  169. ;    None.
  170. ;
  171. ; Output:
  172. ;    Mouse processing is disabled, and the mouse cursor is turned off.
  173. ;
  174. ;*****************************************************************************
  175. hproc    mouse_off <uses ax>
  176.  
  177.     test    mouse_info.mi_flags,1    ; Is there a mouse?
  178.     jz    msof_exit        ; No - never mind
  179.     cli                ; Disallow these for a sec
  180.     and    mouse_info.mi_flags,not 2; Disable mouse processing
  181.     sti                ;
  182.     mov    ax,2            ; Turn the cursor off
  183.     int    33h            ;
  184. msof_exit:
  185.     hret                ; Return to caller
  186.  
  187. hendp
  188.  
  189.  
  190. ;*****************************************************************************
  191. ;
  192. ; void mouse_bounds(int ulrow, int ulcol, int lrrow, int lrcol)
  193. ;
  194. ; Purpose:
  195. ;    Set the bounds for the mouse cursor.
  196. ;
  197. ; Input:
  198. ;    ulrow,
  199. ;    ulcol            Row and column for the upper left corner
  200. ;    lrrow,
  201. ;    lrcol            Row and column for the lower right corner
  202. ;
  203. ; Output:
  204. ;    None. The mouse driver is notified.
  205. ;
  206. ;*****************************************************************************
  207. hproc    mouse_bounds <uses ax bx cx dx> ulr:word, ulc:word, lrr:word, lrc:word
  208.  
  209.     test    mouse_info.mi_flags,1    ; Is there a mouse?
  210.     jz    msbd_exit        ; Nope - exit now
  211.     mov    ax,ulr            ; Get upper row
  212.     mov    dx,lrr            ;  and lower row
  213.     mov    cl,3            ; Gotta multiply by 8 to come out the
  214.     shl    ax,cl            ;  way the mouse driver wants
  215.     shl    dx,cl            ;
  216.     mov    cx,ax            ;
  217.     mov    ax,8            ; Set vertical bounds
  218.     int    33h            ;
  219.     mov    ax,ulc            ; Get left column
  220.     mov    dx,lrc            ;   and right column
  221.     mov    cl,3            ; Multiply them
  222.     shl    ax,cl            ;
  223.     shl    dx,cl            ;
  224.     mov    cx,ax            ;
  225.     mov    ax,7            ; Set horizontal bounds
  226.     int    33h            ;
  227. msbd_exit:
  228.     hret                ; Return to caller
  229.  
  230. hendp
  231.  
  232.  
  233. ;*****************************************************************************
  234. ;
  235. ; void mouse_cursor(int on_off)
  236. ;
  237. ; Purpose:
  238. ;    Turn the mouse cursor on or off.
  239. ;
  240. ; Input:
  241. ;    on_off            Flag indicating whether the mouse cursor
  242. ;                should be turned on or off:
  243. ;                    on_off = 0    Turn it off
  244. ;                    on_off != 0    Turn it on
  245. ;
  246. ; Output:
  247. ;    The mouse cursor is on or off, as desired.
  248. ;
  249. ;*****************************************************************************
  250. hproc    mouse_cursor <uses ax bx> on_off:word
  251.  
  252.     test    mouse_info.mi_flags,1    ; Is there a mouse?
  253.     jz    mscr_exit        ; Nope - don't bother
  254.     mov    bx,on_off        ; Get the flag value
  255.     mov    ax,1            ; Start with ON
  256.     cmp    bx,1            ; See if BX = 0 or not
  257.     adc    ax,0            ; If BX = 0, then AX = 2 (OFF)
  258.     int    33h            ; Call the mouse driver
  259. mscr_exit:
  260.     hret                ; Return to caller
  261.  
  262. hendp
  263.  
  264.  
  265. ;*****************************************************************************
  266. ;
  267. ; int mouse_buttons(void)
  268. ;
  269. ; Purpose:
  270. ;    Get the state of the mouse buttons.
  271. ;
  272. ; Input:
  273. ;    None.
  274. ;
  275. ; Output:
  276. ;    Function returns the button state where:
  277. ;        bit 0 = 1 if the left button is down
  278. ;        bit 1 = 1 if the right button is down
  279. ;
  280. ;*****************************************************************************
  281. hproc    mouse_buttons
  282.  
  283.     sub    ax,ax            ; Just in case it's early exit
  284.     test    mouse_info.mi_flags,1    ; Is there a mouse?
  285.     jz    msbt_exit        ; Nope - exit with 0
  286.     mov    al,mouse_info.mi_buttons; Get the button info
  287.     and    al,3            ; Just in case
  288. msbt_exit:
  289.     hret                ; Return to caller
  290.  
  291. hendp
  292.  
  293.  
  294. ;*****************************************************************************
  295. ;
  296. ; int mouse_in_region(REGION *region_list, int num_regions)
  297. ;
  298. ; Purpose:
  299. ;    Determine whether or not the mouse cursor is in a specific region of
  300. ;    the screen.
  301. ;
  302. ; Input:
  303. ;    region_list        Pointer to a list of region structures
  304. ;    num_regions        Number of elements in that list
  305. ;
  306. ; Output:
  307. ;    Function returns -1 if the mouse cursor is not in any region, or the
  308. ;    index of the region structure.
  309. ;
  310. ;*****************************************************************************
  311. hproc    mouse_in_region <uses bx cx dx ds> rlist:ptr, rnum:word
  312.  
  313.     test    mouse_info.mi_flags,1    ; Is there a mouse?
  314.     jz    mirg_none        ; Nope - return as if not in a region
  315.     mov    cx,rnum            ; Get the number of structures
  316.     sub    dx,dx            ; Start counter at 0
  317.     mov    ax,word ptr mouse_info.mi_row    ; Get the row & column (AL,AH)
  318.     plds    bx,rlist        ; Point to the region list
  319. mirg_l1:
  320.     cmp    al,[bx].r_ulrow        ; See if we're above it
  321.     jb    mirg_l2            ; Yep - not this one
  322.     cmp    al,[bx].r_lrrow        ; See if we're below it
  323.     ja    mirg_l2            ; Yep - not this one
  324.     cmp    ah,[bx].r_ulcol        ; See if we're to the left of it
  325.     jb    mirg_l2            ; Yep - not this one
  326.     cmp    ah,[bx].r_lrcol        ; See if we're to the right of it
  327.     ja    mirg_l2            ; Yep - not this one, period
  328.     mov    ax,dx            ; Get index of this one
  329.     jmp    short mirg_exit        ; Exit now
  330. mirg_l2:
  331.     add    bx,size REGION        ; Point to next one
  332.     inc    dx            ; Count it
  333.     loop    mirg_l1            ; Loop for all of them
  334. mirg_none:
  335. ;
  336. ; Not in any region - return -1
  337. ;
  338.     mov    ax,-1            ; Set return value
  339. mirg_exit:
  340.     hret                ; Return to caller
  341.  
  342. hendp
  343.  
  344.  
  345.     end
  346.